<?php

namespace App\Admin\Grid\Tools;

use App\Admin\Grid;

class CreateButton extends AbstractTool
{
    /**
     * CreateButton constructor.
     * @param Grid $grid
     */
    public function __construct(Grid $grid)
    {
        $this->grid = $grid;
    }

    /**
     * 生成添加按钮的html代码
     *
     * @return string
     */
    public function render()
    {
        if (!$this->grid->allowCreation()) {
            return '';
        }

        return "<a href='/{$this->grid->resource()}/create' class='layui-btn layui-btn-sm'>添加</a>";
    }
}
